package webs.servlet.ServletDemoTwo;
//使用BeanUtils工具类进行数据封装，封装成User对象（JavaBean对象）

import org.apache.commons.beanutils.BeanUtils;
import webs.servlet.domain.User;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/demo9")
public class servletTest_Nine extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        User loginUser=new User();
        Map<String,String[]> parameterMap=req.getParameterMap();
        try
        {
            BeanUtils.populate(loginUser,parameterMap);
            System.out.println(loginUser);
        } catch (IllegalAccessException e)
        {
            e.printStackTrace();
        } catch (InvocationTargetException e)
        {
            e.printStackTrace();
        }

    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        this.doPost(req,resp);
    }
}
